<?php
//Check if the 2nd image exists
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.24-7saddles.com/images/saddles/".$productID."_2.jpg");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);

$data = curl_exec($ch);
curl_close($ch);

preg_match_all("/HTTP\/1\.[1|0]\s(\d{3})/",$data,$matches);

$code = end($matches[1]);

if(!$data) 
{
    $file2Exists = "False";
} 
else 
{
    if($code == 200) 
    {
        $file2Exists = "True";
    } 
    elseif($code == 404) 
    {
        $file2Exists = "False";
    }
}

//Check if the 2nd image exists
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.24-7saddles.com/images/saddles/".$productID."_3.jpg");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);

$data = curl_exec($ch);
curl_close($ch);

preg_match_all("/HTTP\/1\.[1|0]\s(\d{3})/",$data,$matches);

$code = end($matches[1]);

if(!$data) 
{
    $file3Exists = "False";
} 
else 
{
    if($code == 200) 
    {
        $file3Exists = "True";
    } 
    elseif($code == 404) 
    {
        $file3Exists = "False";
    }
}

//Check if the 2nd image exists
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.24-7saddles.com/images/saddles/".$productID."_4.jpg");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);

$data = curl_exec($ch);
curl_close($ch);

preg_match_all("/HTTP\/1\.[1|0]\s(\d{3})/",$data,$matches);

$code = end($matches[1]);

if(!$data) 
{
    $file4Exists = "False";
} 
else 
{
    if($code == 200) 
    {
        $file4Exists = "True";
    } 
    elseif($code == 404) 
    {
        $file4Exists = "False";
    }
}

?>

